import java.util.*;

public class TextDemo {
    public static String reorganizeString(String s){
        if(s.length()<2){
            return s;
        }
        int[] counts = new int[26];
        int maxCount = 0;
        int length = s.length();
        for(int i = 0;i<length;i++){
            char c = s.charAt(i);
            counts[c-'a']++;
            maxCount = Math.max(maxCount,counts[c-'a']);
        }
        if(maxCount>(length+1)/2){
            return "";
        }
        PriorityQueue<Character> queue = new PriorityQueue<>(new Comparator<Character>() {
            @Override
            public int compare(Character o1, Character o2) {
                return counts[o2-'a']-counts[o1-'a'];
            }
        });
        for(char c = 'a';c<='z';c++){
            if(counts[c-'a']>0){
                queue.offer(c);
            }
        }
        StringBuffer sb = new StringBuffer();
        while(queue.size()>1){
            char letter1 = queue.poll();
            char letter2 = queue.poll();
            sb.append(letter1);
            sb.append(letter2);
            counts[letter1-'a']--;
            counts[letter2-'a']--;
            if(counts[letter1-'a']>0){
                queue.offer(letter1);
            }
            if(counts[letter2-'a']>0){
                queue.offer(letter2);
            }
        }
        if(queue.size()>0){
            sb.append(queue.poll());
        }
        return sb.toString();

    }
    public static int findContentChildren(int[] g,int[] s){
        selectionSort(g);
        selectionSort(s);
        int numOfChilren = g.length;
        int numOfCookies = s.length;
        int count = 0;
        for(int i = 0,j = 0;i<numOfChilren && j<numOfCookies;i++,j++){
            while(j<numOfCookies && g[i]>s[j]){
                j++;
            }
            if(j<numOfCookies){
                count++;
            }
        }
        return count;
    }
   public static void  selectionSort(int[] array){
       int maxIndex = 0;
       int minIndex = 0;
       for(int i = 0;i<array.length/2;i++){
           minIndex = i;
           maxIndex = i;
           for(int j = i+1;j<array.length-i;j++){
               if(array[j]>array[maxIndex]) maxIndex = j;
               if(array[j]<array[minIndex]) minIndex = j;
           }
           if(maxIndex==minIndex) break;
           swap(array,minIndex,i);
           if(maxIndex==i) maxIndex = minIndex;
           int lastIndex = array.length-i-1;
           swap(array,lastIndex,maxIndex);
       }
   }
    private static void swap(int[] array,int x,int y){
        int tem = array[x];
        array[x] = array[y];
        array[y] = tem;
    }

    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        int size=list.size();
        String[] array = (String[])list.toArray(new String[size]);
        for(int i=0;i<array.length;i++){
            System.out.println(array[i]);
        }

    }
    public static void main3(String[] args) {
        int[] nums = new int[]{1,1,2,3};
        List<Integer> list = new ArrayList<>();
        for(int i = 0;i<nums.length;i+=2){
            while(nums[i]!=0){
                list.add(nums[i+1]);
                nums[i]--;
            }
        }
        Integer[] array = list.toArray(new Integer[list.size()]);

    }
    public static void main2(String[] args) {
        int[][] array = new int[][]{{1,2},{2,3},{0,1},{2,6}};
        Arrays.sort(array, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1]-o2[1];
            }
        });
        int n = array.length;
        int right = array[0][1];
        int ans = 1;
        for(int i = 1;i<n;i++){
            if(array[i][0]>=right){
                ans++;
                right = array[i][1];
            }
        }

    }
    public static void main1(String[] args) {
        int[] array = new int[]{5,89,1,0,2,5,4,7,9,3,2,6,11,90,21,11,10,21};

    }
}
